<template>
  <el-menu
    :default-active="defaultActive"
    :default-openeds="defaultActiveArray"
    style="border: none; height: 100%"
    :collapse="isCollapse"
    unique-opened
  >
    <BaseMenuSun
      :isCollapse="isCollapse"
      :menuList="menuList"
      @Clicks="clicks"
    ></BaseMenuSun>
  </el-menu>
</template>

<script>
import { nativeplacestore } from "@/utils/base";
import BaseMenuSun from "./_base-MenuSun.vue";
import { gettree } from "./api";
export default {
  name: "Menus",
  components: { BaseMenuSun },
  props: {
    isCollapse: {
      type: Boolean,
      required: false,
    },
  },
  data() {
    return {
      menuList: [{ menuname: "首页", id: -9999, path: "/" }],
    };
  },
  computed: {
    defaultActive() {
      return nativeplacestore.get("defaultActive") || "/";
    },
    defaultActiveArray() {
      if (!nativeplacestore.get("usertree")) {
        return [];
      }
      let a = nativeplacestore
        .get("usertree")
        .filter((v) => v.path == nativeplacestore.get("defaultActive"));
      if (a && a.length > 0) {
        let pd = nativeplacestore
          .get("usertree2")
          .filter((v) => v.id == a[0]["parentId"]);
        return pd && pd.length > 0 ? [pd[0]["path"]] : [];
      }
      return [];
    },
  },
  created() {
    this.gettreeGet();
  },
  methods: {
    async gettreeGet() {
      let a = await gettree({ type: 2 });
      if (a.code == 1000) {
        this.menuList = [...this.menuList, ...a.data];
      } else {
        this.$message({
          showClose: true,
          message: a.data,
          type: "warning",
        });
      }
    },
    clicks(item) {
      if (item.isFrame == 1669180921603084290) {
        // 是否外链
        window.open(item.path);
      } else {
        nativeplacestore.set("defaultActive", item.path);
        this.$router.push(item.path);
      }
    },
  },
};
</script>

<style scoped></style>
